import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  base:'/',
  VITE_APP_BASE_API : "http://api.nong.com/v1/",
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {

    proxy: {
  
     '/api': {//匹配/api开头的请求
  
        target: 'http://api.nong.com/v1',//转发的目标服务器
      
        changeOrigin: true,//允许跨域
      
        rewrite: (path) => path.replace(/^\/api/, '')//在请求转发前移除/api
      
      }
  
    }
  
   }
})